package com.masterclient.app.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;

import com.eoner.baselib.utils.toast.ToastUtil;
import com.eoner.baselibrary.utils.DensityUtil;
import com.masterclient.app.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 拒绝退款
 *
 * @date 2020/6/10.
 */
public class RefuseRefundDialog extends Dialog {

    @BindView(R.id.edit_tv)
    EditText editTv;

    public interface SaveContentCallback {
        void onSaveContent(String content);
    }

    private SaveContentCallback saveContentCallback;

    public RefuseRefundDialog(@NonNull Context context) {
        super(context, R.style.MyDialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_refuse_refund);
        ButterKnife.bind(this);
        setCanceledOnTouchOutside(false);
    }

    public void showDialog(SaveContentCallback saveContentCallback) {
        super.show();
        this.saveContentCallback = saveContentCallback;
        Window window = getWindow();      // 得到dialog的窗体
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.width = (int) (DensityUtil.getScreenWidth(getContext()) * 0.85);
        getWindow().setAttributes(layoutParams);
    }


    @OnClick({R.id.cancel_tv, R.id.confirm_tv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.cancel_tv:
                dismiss();
                break;
            case R.id.confirm_tv:
                String content = editTv.getText().toString().trim();
                if(TextUtils.isEmpty(content)){
                    ToastUtil.showToast("请输入拒绝退款理由，限30字内");
                    return;
                }
                dismiss();
                if(saveContentCallback != null)
                    saveContentCallback.onSaveContent(content);
                break;
        }
    }

}
